/**
 * 
 */
package jdbcEx.examples;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import jdbcEx.examples.util.ConectionManager;

/**
 * @author Dhruva
 * 
 */
public class PrepareCallExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CallableStatement callableStatement = null;
		ResultSet resultSet = null;

		try {
			Connection connection = ConectionManager.getInstance()
					.getConnection();

			callableStatement = connection.prepareCall("{CALL GetToursWithCountByPrice(?,?)}");

			callableStatement.setDouble(1, 400);
			callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
			resultSet = callableStatement.executeQuery();
			
			
			System.out.println(" Number of tours matched your search condition -- "+callableStatement.getInt(2));

			while (resultSet.next()) {

				System.out.println("  " + resultSet.getString("tourName"));
			}

		} catch (Exception exception) {

		} finally {

			try {

				if (resultSet != null) {
					resultSet.close();
				}
				if (callableStatement != null) {
					callableStatement.close();
				}

			} catch (Exception exception) {
				System.out
						.println("Opps Exception occured while closing resources-");
			}

		}

	}

}
